#include "ros/ros.h"
#include <iostream>
#include <string.h>
#include <string> 
#include <iostream>
#include <math.h>
#include <stdlib.h>       
#include <unistd.h>      
#include <serial/serial.h>
serial::Serial Robot_Serial; //声明串口对象
int main(int argc, char** argv)
{	
	int delayStatus = 1,i = 0;
	std::string usart_port;
	int baud_data = 115200;
    ros::init(argc, argv, "starrobot_reboot");
	ros::NodeHandle nh_private("~");
	nh_private.param<std::string>("port", usart_port, "/dev/starrobotbase"); 
 	nh_private.param<int>("baud", baud_data, 115200); 
 	ROS_INFO("Port:%s",usart_port.c_str());
	/**open seril device**/
	try{
		 Robot_Serial.setPort(usart_port);
		 Robot_Serial.setBaudrate(baud_data);
		 serial::Timeout to = serial::Timeout::simpleTimeout(200);
		 Robot_Serial.setTimeout(to);
		 Robot_Serial.open();
  	}
	catch (serial::IOException& e){
		 ROS_ERROR_STREAM("[starrobot] Unable to open serial port, please check device or permission");
	}
	if(Robot_Serial.isOpen())
	{
	 	 ROS_INFO_STREAM("[starrobot] Successful opening of the serial port, data transmission started");
	}
	else
	{
 		ROS_ERROR_STREAM("[starrobot] Unable to open serial port, please check device or permission");
	}
	while(ros::ok() && delayStatus)
	{
		Robot_Serial.setDTR(false);
		Robot_Serial.setRTS(true);
		i++;
		if(i == 2000)
			delayStatus = 0;	
	}
    return 0;
}


